package com.ruoyi.ky450.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.enums.TargetClassEnum;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.ky450.domain.TargetBaseInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ky450.mapper.FixedFacilityElementInfoMapper;
import com.ruoyi.ky450.domain.FixedFacilityElementInfo;
import com.ruoyi.ky450.service.IFixedFacilityElementInfoService;
import org.springframework.util.CollectionUtils;

/**
 * 固定设施要素信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-16
 */
@Service
public class FixedFacilityElementInfoServiceImpl extends ServiceImpl<FixedFacilityElementInfoMapper, FixedFacilityElementInfo> implements IFixedFacilityElementInfoService
{
    @Autowired
    private FixedFacilityElementInfoMapper fixedFacilityElementInfoMapper;

    /**
     * 查询固定设施要素信息
     *
     * @param id 固定设施要素信息主键
     * @return 固定设施要素信息
     */
    @Override
    public FixedFacilityElementInfo selectFixedFacilityElementInfoById(Long id)
    {
        return fixedFacilityElementInfoMapper.selectFixedFacilityElementInfoById(id);
    }

    /**
     * 查询固定设施要素信息列表
     *
     * @param fixedFacilityElementInfo 固定设施要素信息
     * @return 固定设施要素信息
     */
    @Override
    public List<FixedFacilityElementInfo> selectFixedFacilityElementInfoList(FixedFacilityElementInfo fixedFacilityElementInfo)
    {
        return fixedFacilityElementInfoMapper.selectFixedFacilityElementInfoList(fixedFacilityElementInfo);
    }

    /**
     * 新增固定设施要素信息
     *
     * @param fixedFacilityElementInfo 固定设施要素信息
     * @return 结果
     */
    @Override
    public int insertFixedFacilityElementInfo(FixedFacilityElementInfo fixedFacilityElementInfo)
    {
        fixedFacilityElementInfo.setCreateTime(DateUtils.getNowDate());
        return fixedFacilityElementInfoMapper.insertFixedFacilityElementInfo(fixedFacilityElementInfo);
    }

    /**
     * 修改固定设施要素信息
     *
     * @param fixedFacilityElementInfo 固定设施要素信息
     * @return 结果
     */
    @Override
    public int updateFixedFacilityElementInfo(FixedFacilityElementInfo fixedFacilityElementInfo)
    {
        fixedFacilityElementInfo.setUpdateTime(DateUtils.getNowDate());
        return fixedFacilityElementInfoMapper.updateFixedFacilityElementInfo(fixedFacilityElementInfo);
    }

    /**
     * 批量删除固定设施要素信息
     *
     * @param ids 需要删除的固定设施要素信息主键
     * @return 结果
     */
    @Override
    public int deleteFixedFacilityElementInfoByIds(Integer[] ids)
    {
        return fixedFacilityElementInfoMapper.deleteFixedFacilityElementInfoByIds(ids);
    }

    /**
     * 删除固定设施要素信息信息
     *
     * @param id 固定设施要素信息主键
     * @return 结果
     */
    @Override
    public int deleteFixedFacilityElementInfoById(Long id)
    {
        return fixedFacilityElementInfoMapper.deleteFixedFacilityElementInfoById(id);
    }

    @Override
    public FixedFacilityElementInfo getFixedFacilityByTBInfoId(Long id) {
        List<FixedFacilityElementInfo> list = list(queryWrapperByBaseInfoId(id));
        if(!CollectionUtils.isEmpty(list)){
            return list.get(0);
        }
        return null;
    }

    @Override
    public int deleteFacilityByBaseInfoId(Long id) {
        return fixedFacilityElementInfoMapper.delete(queryWrapperByBaseInfoId(id));
    }

    private QueryWrapper<FixedFacilityElementInfo> queryWrapperByBaseInfoId(Long id){
        QueryWrapper<FixedFacilityElementInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("target_base_info_id", id);
        return wrapper;
    }
}
